
package cz.cvut.fel.y36mm1.videostreaming.server;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

/**
 * Screen displaying recieved images
 * @author Jiri Chadima, chadij1
 */
public class ServerVideoScreen extends ServerAbstractScreen {

	Image current = null;

	/**
	 * Creates new image and repaints
	 * @param image
	 */
	public void showImage(byte[] image) {
		current = Image.createImage(image, 0, image.length);
		repaint();
	}


	/**
	 * if no current image is set, draw black screen, draw image otherwise
	 * @param g
	 */
	protected void paint(Graphics g) {
		if(current != null) {
			int width = getWidth();
			int height = getHeight();
			int imgh = current.getHeight();
			int imgw = current.getWidth();

			int finalw = (width /2) - (imgw /2);
			int finalh = (height / 2) - (imgh/2);
			
			g.drawImage(current, finalw, finalh, 0);
		} else {
			g.setColor(0x000000);
			g.fillRect(0, 0, getWidth(), getHeight());
		}
	}

}
